<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/6/29
 * Time: 上午11:12
 */

namespace app\mall\controller;


use think\Request;

class Order extends Auth
{
    /**
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function confirm (Request $request) {
        $order_no       =   $request->post('order_no');
        return \app\mall\logic\Order::confirm($order_no, self::$uid);
    }
    /**
     * @purpose 通过订单编号获取订单详情
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function detailByOrderNo (Request $request)
    {
        $order_no       = $request->get('order_no', '');
        return \app\mall\logic\Order::detailByOrderNo($order_no, self::$uid);
    }
    /**
     * @purpose 通过状态获取订单列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function itemByStatus(Request $request)
    {
        $page   = $request->get('page', 1);
        $size   = $request->get('size', 20);
        $status = $request->get('status', 0);
        return \app\mall\logic\Order::itemByStatus(self::$uid,$status, $page, $size);
    }
    /**
     * @purpose 查询用户每个订单状态的数量
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function statusNumber ()
    {
        return \app\mall\logic\Order::statusNumber(self::$uid);
    }
    /**
     * 用户下单
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function placeAnOrder (Request $request)
    {
        $data       =   $request->post();
        return \app\mall\logic\Order::placeAnOrder($data, self::$uid);
    }
    /**
     * @purpose 确定订单商品列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function itemByConfirm (Request $request)
    {
        $data = $request->post();
        if ($data['type'] === 'cart') {
            return \app\mall\logic\Order::itemForCart($data['data'], self::$uid);
        }
        if ($data['type'] === 'direct') {
            return \app\mall\logic\Order::itemForGoods(
                $data['data']['goods_id'],
                $data['data']['goods_number'],
                $data['data']['nums']);
        }
    }

    /**
     * @purpose 取消订单
     * @param Request $request
     * @return array
     */
    public function cancel (Request $request) {
        $reason     = $request->post('reason');
        $order_no   = $request->post('order_no');
        return \app\mall\logic\Order::cancel($order_no, $reason, self::$uid);
    }

    /**
     * @purpose 删除订单
     * @param Request $request
     * @return array
     */
    public function delete (Request $request) {
        $order_no   = $request->post('order_no');
        return \app\mall\logic\Order::delete($order_no, self::$uid);
    }
}